import type { AxiosError, AxiosRequestConfig, AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from "axios"
import type { ResponseData, RequestOptions } from "../types"

export interface CustomCreateAxiosDefaults extends CreateAxiosDefaults {
    transform?: AxiosTransform
    requestOptions?: RequestOptions
}

export interface AxiosRequestConfigExtension {
    requestOptions?: RequestOptions
}

export abstract class AxiosTransform {
    /**
     * @description: 请求之前处理配置
     * @description: Process configuration before request
     */
    beforeRequestHook?: (config: AxiosRequestConfig, options: RequestOptions) => void

    /**
     * @description: 请求成功处理
     */
    transformResponseData?: (res: AxiosResponse<ResponseData>, options: RequestOptions) => any

    /**
     * @description: 请求失败处理
     */
    requestCatch?: (e: Error) => Promise<any>

    /**
     * @description: 请求之前的拦截器
     */
    requestInterceptors?: (config: InternalAxiosRequestConfig, options: RequestOptions) => void

    /**
     * @description: 请求之后的拦截器
     */
    responseInterceptors?: (res: AxiosResponse<any>) => AxiosResponse<any>

    /**
     * @description: 请求之前的拦截器错误处理
     */
    requestInterceptorsCatch?: (error: Error) => void

    /**
     * @description: 请求之后的拦截器错误处理
     */
    responseInterceptorsCatch?: (error: AxiosError) => void
}
